package com.atguigu.spring.config;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @author 孙志鹏
 * @create 2021-06-13 11:13
 */
public class MyBeanPost implements BeanPostProcessor {

    /**
     * Bean初始化之前方法
     * @param bean     类
     * @param beanName 类名称
     * @return
     * @throws BeansException
     */
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("Bean初始化方法之前执行：" + beanName);
        return bean;
    }


    /**
     * Bean初始化之后方法
     * @param bean      类
     * @param beanName  类名称
     * @return
     * @throws BeansException
     */
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("Bean初始化方法之后执行：" + beanName);
        return bean;
    }
}
